package com.menggudf.common;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author zengqd
 */
@Data
public class RespResult<T> implements Serializable {
    /**
     * 状态码
     */
    private String code;
    /**
     * 描述
     */
    private String msg;
    /**
     * 对象
     */
    private T data;
    /**
     * 运单号
     */
    private String shipmentNo;

    /**
     * 返回成功标记
     *
     * @param obj 数据对象
     * @return 返回实体
     */
    public static <T> RespResult<T> ok(T obj) {
        RespResult<T> respResult = new RespResult<>();
        respResult.setCode(ResultCode.SUCCESS.getCode());
        respResult.setMsg(ResultCode.SUCCESS.getMsg());
        respResult.setData(obj);
        return respResult;
    }

    /**
     * 返回成功标记
     *
     * @param obj 数据对象
     * @return 返回实体
     */
    public static <T> RespResult<T> ok(T obj,String shipmentNo) {
        RespResult<T> respResult = new RespResult<>();
        respResult.setCode(ResultCode.SUCCESS.getCode());
        respResult.setMsg(ResultCode.SUCCESS.getMsg());
        respResult.setData(obj);
        respResult.setShipmentNo(shipmentNo);
        return respResult;
    }


    /**
     * 返回成功标记
     *
     * @param obj 数据对象
     * @return 返回实体
     */
    public static <T> RespResult<T> ok(T obj,String msg,String shipmentNo) {
        RespResult<T> respResult = new RespResult<>();
        respResult.setCode(ResultCode.SUCCESS.getCode());
        respResult.setMsg(msg);
        respResult.setData(obj);
        return respResult;
    }

    public RespResult() {
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMsg();
        this.data = null;
    }


    /**
     * 返回失败标记
     *
     * @param code 状态码
     * @param msg  状态信息
     * @return 返回实体
     */
    public static <T> RespResult<T> fail(String code, String msg) {
        RespResult<T> respResult = new RespResult<>();
        respResult.setCode(code);
        respResult.setMsg(msg);
        return respResult;
    }

    /**
     * 默认失败返回对象
     * @return 失败返回的对象
     * @param <T> 范型
     */
    public static <T>  RespResult<T> fail(){
        RespResult<T> respResult = new RespResult<>();
        respResult.setCode(ResultCode.SYSTEM_EXECUTION_ERROR.getCode());
        respResult.setMsg(ResultCode.SYSTEM_EXECUTION_ERROR.getMsg());
        return respResult;
    }

    /**
     * 返回错误对象
     * @param msg 错误信息
     * @return 返回的实体类
     * @param <T> 范型实体类
     */
    public static <T> RespResult<T> fail(String msg) {
        return fail(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), msg);
    }


}
